package com.siwei.mes.entity.experiment.slag;

import com.alibaba.fastjson.JSONObject;
import com.siwei.mes.common.util.JsonUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @Description: 矿渣粉-样品密度
 * @Version: 1.0
 * @author: YANGKE
 * @date: 2024/02/25 21:29
 */
@Data
@Accessors(chain = true)
public class SlagYpmd {
    @ApiModelProperty(value = "平均值")//1
    private String pjz = "";
    @ApiModelProperty(value = "单项结论")//1
    private String dxjl = "";
    @ApiModelProperty(value = "检测日期")
    private String jcrq = "";

    @ApiModelProperty(value = "样品密度信息")
    private List<SlagYpmd.YpmdInfo> ypmdInfo = Collections.singletonList(new SlagYpmd.YpmdInfo());

    @Data
    @Accessors(chain = true)
    @ApiModel("样品密度信息")
    public static class YpmdInfo {
        @ApiModelProperty(value = "试验质量")
        private String syzl = "";

        @ApiModelProperty(value = "第一次读数")
        private String dycdsv1 = "";

        @ApiModelProperty(value = "第二次读数")
        private String decdsv2 = "";

        @ApiModelProperty(value = "检验结果")
        private String sywz = "";
    }

    /**
     * 字符串转成对象 然后再转成json
     *
     * @param object
     * @return
     */
    private static JSONObject toJsonObject(Object object) {
        SlagYpmd entity = new SlagYpmd();
        if (object == null) {
            return JsonUtils.beanToObject(entity);
        }
        if (object instanceof String) {
            entity = JsonUtils.getObject((String) object, SlagYpmd.class);
        } else if (object instanceof JSONObject) {
            entity = JsonUtils.getObject((JSONObject) object, SlagYpmd.class);
        }
        return JsonUtils.beanToObject(entity);
    }

    public static String checkIsMust(JSONObject objJson, String name) {
        if (objJson.isEmpty()) {
            return null;
        }
        SlagYpmd entity = JsonUtils.getObject(objJson, SlagYpmd.class);
        if (entity == null) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        if (StringUtils.isBlank(entity.getPjz()) || "null".equals(entity.getPjz())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        /*if (StringUtils.isBlank(entity.getDxjl()) || "null".equals(entity.getDxjl())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }*/
        return null;
    }

    public static void setValue(SlagYpmd entity, Map<String, Object> data) {
        if(data.get("MiDuPingJun") != null){
            entity.setPjz(data.get("MiDuPingJun").toString());
        }
        if(data.get("conclusion") != null){
            entity.setDxjl(data.get("conclusion").toString());
        }
        List<SlagYpmd.YpmdInfo> ypmdInfo = entity.getYpmdInfo();
        if(data.get("ShuiNiZhiLiang1") != null){
            ypmdInfo.get(0).setSyzl(data.get("ShuiNiZhiLiang1").toString());
        }
        if(data.get("ShuiNiZhiLiang1") != null){
            ypmdInfo.get(0).setDycdsv1(data.get("ShuiNiZhiLiang1").toString());
        }
        if(data.get("YiZhuangYeMian1") != null){
            ypmdInfo.get(0).setDecdsv2(data.get("YiZhuangYeMian1").toString());
        }
        if(data.get("MiDu1") != null){
            ypmdInfo.get(0).setSywz(data.get("MiDu1").toString());
        }
    }
}
